package nl.rainbowsheep.reisorg.rest.service.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

/**
 * Role is a SQL reserved word, for that reason we decided
 * to rename Role to BurritoRole. 
 */
@Entity
@Table(name = "burrito_roles")
public class BurritoRole implements Serializable {

    protected BurritoRole() {
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "burrito_role_id")
    private Integer id;

    @Column(name = "burrito_role")
    @NotNull
    private String burritoRole;

    @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    @JoinTable(name = "burrito_user_roles",
            joinColumns = {
                @JoinColumn(name = "burrito_role_fk")},
            inverseJoinColumns = {
                @JoinColumn(name = "burrito_user_fk")})   
    //JsonIgnore decides who is the slave in the relationship. 
    //I.E. burritoRole-burritoUser relations can't not be changed through a BurritoRole object.
    @JsonIgnore
    private List<BurritoUser> burritoUsers;

    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getBurritoRole() {
        return burritoRole;
    }

    public void setBurritoRole(String burritoRole) {
        this.burritoRole = burritoRole;
    }

    public List<BurritoUser> getBurritoUsers() {
        return burritoUsers;
    }

    public void setBurritoUsers(List<BurritoUser> burritoUsers) {
        this.burritoUsers = burritoUsers;
    }
}
